﻿@model CMSApplication.Areas.Administration.Models.WorkSearchModel
@{
    ViewBag.Title = "QL Cong viec";
}

<script>
    function GetDataForSearch(_data) {
        var assign_on_from = ParseTime($("#AssignOnFrom").val());
        var assign_on_to = ParseTime($("#AssignOnTo").val());
        return {
            Keys: $("#Keys").val(),
            CustomerId: parseInt($("#CustomerId").val()),
            StaffId: parseInt($("#StaffId").val()),
            AssignOnFrom: assign_on_from != null ? assign_on_from.toISOString() : null,
            AssignOnTo: assign_on_to != null ? assign_on_to.toISOString() : null,
            Status: parseInt($("#Status").val()),
            OrderBy: parseInt($("#OrderBy").val()),
            Page: parseInt($("#Page").val()),
            Type: parseInt($("#Type").val())
        };
    };

    function ExecForSearch(_data) {
        if (!IsNullOrEmpty(_data.page)) { $("#Page").val(_data.page) };
        if (!IsNullOrEmpty(_data.type)) { $("#Type").val(_data.type) };
        var data = GetDataForSearch({});
        if (data.Type == 1) {
            Ajax({
                url: "/Work/List",
                data: data,
                ExecSuccess: function (result) {
                    $(".list").html(result.dataServer);
                    if (_data.isNotify) {
                        $.pnotify({
                            title: "Thông báo",
                            text: "Tìm kiếm hoàn tất",
                            type: "info",
                            opacity: .8
                        });
                    }
                }
            });
        } else {
            DownloadFile({ action: "/Work/List", data: data });
            $.pnotify({
                title: "Thông báo",
                text: "Xuất excel thành công",
                type: "info",
                opacity: .8
            });
        }
    };
    
    jQuery(document).ready(function ($) {
        $("#AssignOnFrom, #AssignOnTo").datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true
        });
        $("#AssignOnFrom").datepicker("option", "onClose", function (selectedDate) {
            $("#AssignOnTo").datepicker("option", "minDate", selectedDate);
        });
        $("#AssignOnTo").datepicker("option", "onClose", function (selectedDate) {
            $("#AssignOnFrom").datepicker("option", "maxDate", selectedDate);
        });

        $(".head").on("click", "[action-name='Search']", function (e) {
            ExecForSearch({ page: 1, type: 1, isNotify: true });
        });

        $(".head").on("click", "[action-name='ExportExcel']", function (e) {
            ExecForSearch({ type: 2, isNotify: true });
        });

        ExecForSearch({ });
    });
</script>

@Html.HiddenFor(model => model.Page)
@Html.HiddenFor(model => model.Type)

<div class="row-fluid">
    <div class="span2">
        <span>Từ khóa</span>
    </div>
    <div class="span10">
        @Html.TextBoxFor(model => model.Keys, new { @style = "width:calc(100% - 14px);", @placeholder = "Tìm kiếm theo hóa đơn, nội dung, ghi chú,..." })
    </div>
</div>

<div class="row-fluid">
    <div class="span2">
        <span>Khách hàng</span>
    </div>
    <div class="span4">
        @Html.DropDownListFor(model => model.CustomerId, Model.SLCustomer, new { @style = "width:100%;" })
    </div>
    <div class="span2">
        <span>Nhân viên</span>
    </div>
    <div class="span4">
        @Html.DropDownListFor(model => model.StaffId, Model.SLStaff, new { @style = "width:100%;" })
    </div>
</div>

<div class="row-fluid">
    <div class="span2">
        <span>Ngày thực hiện (từ)</span>
    </div>
    <div class="span4">
        <input type="text" id="AssignOnFrom" name="AssignOnFrom" value="@if(Model.AssignOnFrom > DateTime.MinValue) {<text>@string.Format("{0:dd/MM/yyyy}", Model.AssignOnFrom)</text>} else { }" placeholder="Chọn ngày thực hiện (từ)" style="width:calc(100% - 14px);" />
    </div>
    <div class="span2">
        <span>Ngày thực hiện (đến)</span>
    </div>
    <div class="span4">
        <input type="text" id="AssignOnTo" name="AssignOnTo" value="@if(Model.AssignOnTo > DateTime.MinValue) {<text>@string.Format("{0:dd/MM/yyyy}", Model.AssignOnTo)</text>} else { }" placeholder="Chọn ngày thực hiện (đến)" style="width:calc(100% - 14px);" />
    </div>
</div>

<div class="row-fluid">
    <div class="span2">
        <span>Trạng thái</span>
    </div>
    <div class="span4">
        @Html.DropDownListFor(model => model.Status, Model.SLStatus, new { @style = "width:100%;" })
    </div>
    <div class="span2">
        <span>Sắp xếp theo</span>
    </div>
    <div class="span4">
        @Html.DropDownListFor(model => model.OrderBy, Model.SLOrderBy, new { @style = "width:100%;" })
    </div>
</div>

<div class="head">
    <div class="isw-grid"></div>
    <h1>Quản lý công việc</h1>
    <ul class="buttons">
        <li><a title="Thêm mới" href="@Url.Action("Add", "Work", new { })" class="isw-plus"></a></li>
        <li><a title="Xuất excel" href="javascript:void(0);" class="isw-attachment" action-name="ExportExcel"></a></li>
        <li><a title="Tìm kiếm" href="javascript:void(0);" class="isw-zoom" action-name="Search"></a></li>
        @*
        <li><a href="#" class="isw-download"></a></li>
        <li>
            <a href="#" class="isw-settings"></a>
            <ul class="dd-list">
                <li>
                    <a href="@Url.Action("Add", "Work", new { })">
                        <span class="isw-plus"></span>Thêm mới
                    </a>
                </li>
                <li>
                    <a action-name="ExportExcel" href="javascript:void(0);">
                        <span class="isw-attachment"></span> Xuất excel
                    </a>
                </li>
                <li><a href="#"><span class="isw-edit"></span> Edit</a></li>
                <li><a href="#"><span class="isw-delete"></span> Delete</a></li>
            </ul>
        </li>*@
    </ul>
    <div class="clear"></div>
</div>
<div class="block-fluid table-sorting">
    <div class="row-fluid list"></div>
</div>
